#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
int n,a1,b1,c1,d1,e1,a[1260],b[1260],c[1260],d[1260],e[65540],aa[260],bb[260],cc[260],dd[260],ee[65540],p1;
char s[99],a2,a3,a4,a5;
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for(int q=1;q<=n;q++){
		scanf(" %s %d%c%d%c%d%c%d%c%d",&s,&a1,&a2,&b1,&a3,&c1,&a4,&d1,&a5,&e1);
		if(a2!='.'||a3!='.'||a4!='.'||a5!=':'||a1<0||a1>255||b1<0||b1>255||c1<0||c1>255||d1<0||d1>255||e1<0||e1>65535){
			printf("ERR\n");
			continue;
		}
		if(s[0]=='S'){
			p1++;
			a[p1]=a1;
			b[p1]=b1;
			c[p1]=c1;
			d[p1]=d1;
			e[p1]=e1;
			printf("OK\n");
		}
		else{
			int p=1;
			for(int w=1;w<=p1;w++){
				if(a[w]!=a1){
					continue;
				}
				if(b[w]!=b1){
					continue;
				}
				if(c[w]!=c1){
					continue;
				}
				if(d[w]!=d1){
					continue;
				}
				if(e[w]!=e1){
					continue;
				}
				printf("%d\n",w);
				p=0;
				break;
			}
			if(p==1)printf("FAIL\n");
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
